#include<bits/stdc++.h>
using namespace std;
#define int long long
#define debug cout<<-1<<endl
const int maxn=105;
int t;
int n,a[maxn];
int ans;
int vis[maxn][maxn][2][2][maxn];
void dfs(int id,int la,int fn,int fl,int sum){
    if(vis[id][la][fn][fl][sum]==1&&id>=4&&la>=4&&sum>0)return;
    vis[id][la][fn][fl][sum]=1;
    if(id>n){
        //cout<<ans<<id<<la<<fn<<fl<<endl;
        ans=max(ans,sum);
        return;
    }
    if(fl==-1){
        dfs(id+1,0,0,1,sum);
        dfs(id+1,0,1,0,sum);
        dfs(id+1,0,0,0,sum);
        dfs(id+1,0,1,1,sum);
    }
    if(fn==1&&fl==1){
        if(a[id]==a[id-1])sum+=a[id];
        dfs(id+1,la,0,1,sum);
        dfs(id+1,la,1,1,sum);
    }
    else if(fn==1&&fl==0){
        if(a[id]==a[la])sum+=a[id];
        dfs(id+1,id-1,0,1,sum);
        dfs(id+1,id-1,1,1,sum);
    }
    else if(fn==0&&fl==1){
        if(a[id]==a[la])sum+=a[id];
        dfs(id+1,id-1,1,0,sum);
        dfs(id+1,id-1,0,0,sum);
    }
    else{//0 0
        //cout<<id<<a[id]<<id-1<<a[id-1]<<endl;
        if(a[id]==a[id-1])sum+=a[id];
        dfs(id+1,la,0,0,sum);
        dfs(id+1,la,1,0,sum);
    }
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        for(int i=1;i<=100;i++){
            for(int j=1;j<=100;j++){
                for(int k=1;k<=100;k++){

                    vis[i][j][0][0][k]=-1;
                    vis[i][j][1][1][k]=-1;
                    vis[i][j][0][1][k]=-1;
                    vis[i][j][1][0][k]=-1;
                }
            }
        }

        memset(a,0,sizeof(a));
        a[0]=-1;
        ans=0;
        scanf("%lld",&n);
        for(int i=1;i<=n;i++){
            scanf("%lld",&a[i]);
        }

        dfs(1,0,1,-1,0);
        cout<<ans<<endl;
    }
    //cout<<(double)clock()/CLOCKS_PER_SEC<<endl;


}
